<?php

/**
 * secure actions.
 *
 * @package    symfony
 * @subpackage secure
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class secureActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeLogin()
  {
      //if ($this->getRequestParameter('login') == 'asd' && $this->getRequestParameter('password') == 'asd')
      if ($this->getRequestParameter('login') && $this->getRequestParameter('password'))
      {

             $u = Doctrine_Core::getTable('sfGuardUser')
              ->createQuery('a')
              ->addWhere('username = ?',$this->getRequestParameter('login'))
              ->addWhere('is_super_admin = 1')
              ->execute()->getFirst();

             $haslo = sha1($u->salt.$this->getRequestParameter('password'));

      $u2 = Doctrine_Core::getTable('sfGuardUser')
              ->createQuery('a')
              ->addWhere('username = ?',$this->getRequestParameter('login'))
              ->addWhere('password = ?', $haslo)
              ->addWhere('is_super_admin = 1')
              ->execute()->getFirst();

      if ($u2) {
        $this->getUser()->setAuthenticated(true);

        return $this->redirect('sfGuardUser/index');
      }

      
      }
      else
      {
        //$this->getRequest()->setError('login', 'incorrect entry');
      }

      $this->setLayout(false);
  }


  public function executeLogout()
    {
      $this->getUser()->setAuthenticated(false);

      return $this->redirect('/');
    }



}
